package com.jxb.first;

import java.util.Stack;

/**
 * 用栈实现队列
 */
public class ImplQueueUsingStacks_232 {

    public static void main(String[] args) {

    }

    static class MyQueue {
        private static Stack<Integer> inStack;
        private static Stack<Integer> outStack;

        public void push(int x) {
            inStack.push(x);
        }

        public int pop() {
            if (outStack.empty()) {
                in2out();
            }
            return outStack.pop();
        }

        public int peek() {
            if (outStack.isEmpty()) {
                in2out();
            }
            return outStack.peek();
        }

        private void in2out() {
            while (!inStack.isEmpty()) {
                outStack.push(inStack.pop());
            }
        }
    }

}
